package com.example.viewpager

import android.animation.ObjectAnimator
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.example.viewpager.databinding.ActivityMainBinding
import com.example.viewpager.databinding.FragmentScaleBinding
import java.util.*
import kotlin.random.Random
import kotlin.random.Random.Default.nextBoolean

class ScaleFragment : Fragment() {


    lateinit var binding: FragmentScaleBinding;

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
         binding = FragmentScaleBinding.inflate(inflater)
        return inflater.inflate(R.layout.fragment_scale, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        binding.imageViewScale.setOnClickListener {
            Log.d("TAG", "onActivityCreated: 点击了缩放")
            val factor =if(Random.nextBoolean()) 0.1f else -0.1f
            ObjectAnimator.ofFloat(it,"scaleX",it.scaleX +factor).start()
            ObjectAnimator.ofFloat(it,"scaleY",it.scaleY +factor).start()
        }

    }
}